import { container } from 'tsyringe';
import { getAllOnDestory, getAllOnInit } from '../../tokens/core';
import { mainInit } from './mainInit';
import { ServiceNotEnabled } from '../../core/exception';
import { mainRegister } from './mainRegister';
export function mainBootstrap() {
    if (auto.service === null) {
        app.startActivity({
            action: "android.settings.ACCESSIBILITY_SETTINGS"
        });
        return;
    }
    auto.waitFor();
    if (auto.service == null) {
        toast("请先开启无障碍服务！");
        return;
    }
    if (device.height === 0 || device.width === 0) {
        throw new ServiceNotEnabled(
            'Failed to get the screen size. ' +
            'Please try restarting the service or re-installing Hamibot'
        );
    } else {
        console.log("Screen size: " + device.height + " x " + device.width);
    }
    mainRegister();
    /**
     * 注册系统启动钩子
     */
    mainInit();
    /**
     * 系统初始化
     */
    const onInits = getAllOnInit();
    onInits.map(init => init());
    /**
     * 根据设置 判断运行脚本类型
     */
    const interval = setInterval(()=>{}, 1000)
    events.on('exit', () => {
        const onDestory = getAllOnDestory()
        onDestory.map(destory => destory())
        container.dispose()
        clearInterval(interval)
    })
}
